package com.theo.mapper;

import com.theo.entity.StockInfo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author 方涛
 * @since 2021-02-02
 */
@Repository
public interface StockInfoMapper extends BaseMapper<StockInfo> {

    int saveStockInfo(StockInfo stockInfo);

    int deleteStockInfo(Integer id);

    int updateSotckInfo(Integer id);

    @Select("SELECT `stock_id`,`article_id`,`mask_name` `article_name`,`hospital_name`,temp.`hospital_id`,temp.`stock_num`,temp.`unit`,temp.`status`,temp.`create_time`\n" +
            "FROM `hospital_info` h INNER JOIN \n" +
            "(\n" +
            "SELECT s2.`article_id`,a1.`mask_name`,s2.`stock_id`,s2.`hospital_id`,s2.`stock_num`,s2.`unit`,s2.`status`,s2.`create_time`\n" +
            "FROM `stock_info` s2 INNER JOIN `mask_info` a1\n" +
            "ON s2.`article_id` = a1.`mask_id`\n" +
            ") temp ON h.`hospital_id`=temp.`hospital_id`")
    List<StockInfo> queryAllStockInfo();

    StockInfo queryStockInfoById(Integer id);

    @Select("SELECT `stock_id`,`article_id`,`mask_name` `article_name`,`hospital_name`,temp.`hospital_id`,temp.`stock_num`,temp.`unit`,temp.`status`,temp.`create_time`\n" +
            "FROM `hospital_info` h INNER JOIN \n" +
            "(\n" +
            "SELECT s2.`article_id`,a1.`mask_name`,s2.`stock_id`,s2.`hospital_id`,s2.`stock_num`,s2.`unit`,s2.`status`,s2.`create_time`\n" +
            "FROM `stock_info` s2 INNER JOIN `mask_info` a1\n" +
            "ON s2.`article_id` = a1.`mask_id`\n" +
            ") temp ON h.`hospital_id`=temp.`hospital_id`\n" +
            "WHERE temp.`status`= 0 and temp.`hospital_id` = #{id}")
    List<StockInfo> queryStockInfoByHospitalId(Integer id);

    StockInfo queryStockInfoByArticleId(Integer id);
}
